<?php

use yii\db\Migration;

class m181025_122601_create_user_package_pool extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%user_package_pool}}', [
            'id' => $this->primaryKey(),
            'uid' => $this->integer()->notNull()->comment('用户编号'),
            'package_id' => $this->integer()->notNull()->comment('套餐编号'),
            'month' => $this->char(6)->notNull()->comment('月份'),
            'data_pool' => $this->decimal(20, 4)->notNull()->defaultValue(0)->comment('流量池'),
            'data_used' => $this->decimal(20, 4)->notNull()->defaultValue(0)->comment('使用量'),
        ]);
        $this->createIndex('fk_user_package_pool_user1_idx', '{{%user_package_pool}}', ['uid']);
        $this->addForeignKey('fk_user_package_pool_user1', '{{%user_package_pool}}', ['uid'], '{{%user}}', ['id']);
        $this->createIndex('fk_user_package_pool_package1_idx', '{{%user_package_pool}}', ['package_id']);
        $this->addForeignKey('fk_user_package_pool_package1', '{{%user_package_pool}}', ['package_id'], '{{%user}}', ['id']);
        $this->createIndex('user_package_pool_month_idx', '{{%user_package_pool}}', ['month']);
    }

    public function safeDown()
    {
        $this->dropTable('{{%user_package_pool}}');
    }
}
